//
//  workbenchViewController.m
//  DJS
//
//  Created by mac on 2017/12/26.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "workbenchViewController.h"
#import "workbenchView.h"
@interface workbenchViewController ()
@property(nonatomic,strong)workbenchView *aView;
@end

@implementation workbenchViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self wr_setNavBarBackgroundAlpha:1];
    self.navigationItem.title=@"我的工作台";
    _aView=[workbenchView new];
    [self.view addSubview:_aView];
    [_aView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.bottom.mas_equalTo(0);
    }];
    [_aView creatView];
    _aView.viewController=self;
    
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    
    //设置图片
    UIImage *imageForButton = [UIImage imageNamed:@"在线客服"];
    [button setImage:imageForButton forState:UIControlStateNormal];
    
    //设置文字
    NSString *buttonTitleStr = @"客服";
    [button setTitle:buttonTitleStr forState:UIControlStateNormal];
    button.titleLabel.font = [UIFont systemFontOfSize:15];
    [button setTitleColor:_backgroundColor forState:UIControlStateNormal];
    
    button.frame = CGRectMake(0, 0 , 50, 50);   //#1#硬编码设置UIButton位置、大
    
    button.titleEdgeInsets = UIEdgeInsetsMake(0, -button.imageView.frame.size.width, -button.imageView.frame.size.height, 0);
    // button.imageEdgeInsets = UIEdgeInsetsMake(-button.titleLabel.frame.size.height, 0, 0, -button.titleLabel.frame.size.width);
    // 由于iOS8中titleLabel的size为0，用上面这样设置有问题，修改一下即可
    button.imageEdgeInsets = UIEdgeInsetsMake(-button.titleLabel.intrinsicContentSize.height, 0, 0, -button.titleLabel.intrinsicContentSize.width);
    [button addTarget:self action:@selector(bodaDianhua) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem * right=[[UIBarButtonItem alloc]initWithCustomView:button];
    //将整个viewBackInNavi右移10
    UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc]   initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace   target:nil action:nil];
    negativeSpacer.width =-30;//负数为右移，正数为左移
    
    self.navigationItem.rightBarButtonItems = [NSArray arrayWithObjects:negativeSpacer,right, nil];

}
-(void)viewWillAppear:(BOOL)animated{
    [self loginView];
}

-(void)loginView{
    _aView.userDic=nil;
    NSDictionary *userDic = [NSKeyedUnarchiver unarchiveObjectWithFile:_userModelFile];
    NSString *token=[userDic objectForKey:@"token"];
    NSNumber *waiter_id1=[userDic objectForKey:@"waiter_id"];
    NSString *waiter_id=[NSString stringWithFormat:@"%@",waiter_id1];
    
    NSDictionary *dic=[NSDictionary dictionaryWithObjectsAndKeys:@"0",@"waiter_role",@"1",@"user_role",token,@"token",waiter_id,@"waiter_id", nil];
    [ZQTools AFNPostDataUrl:@"waiter/waiter/waiter_info" Dict:dic andTableView:nil andViewController:self andSuccessBlock:^(id responseObject) {
        [ZQTools cleanViewSubviews:_aView];
        _aView.userDic=responseObject;
        [_aView creatView];
    } anderrorBlock:nil];
    
}

-(void)bodaDianhua{
    [ZQTools AFNPostDataUrl:@"api/index/get_service_phone" Dict:nil andTableView:nil andViewController:self andSuccessBlock:^(id responseObject) {
        
        
        NSMutableString *str=[[NSMutableString alloc] initWithFormat:@"tel:%@",responseObject];
        UIWebView *callWebview = [[UIWebView alloc] init];
        [callWebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]]];
        [self.view addSubview:callWebview];
        
       
    } anderrorBlock:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
